<template>
	<view>
		<view class="content">
			<view>
				<input type="text" value="" placeholder="用户名" v-model="params.accountNum" />
			</view>
			<view>
				<input type="text" value="" placeholder="密码" v-model="params.passWord" />
			</view>
			<button type="default" @click="customerRegistered">注册</button>
		</view>
		<view class="content">
			<view>
				<input type="text" value="" placeholder="用户名" v-model="paramss.accountNum" />
			</view>
			<view>
				<input type="text" value="" placeholder="密码" v-model="paramss.passWord" />
			</view>
			<button type="default" @click="customerLogin">登录</button>
		</view>
		<button type="default" @click="showUserInfo">显示用户信息</button>
		<button type="default" @click="getNetWork">获取所有推荐网点</button>
		
		<view class="content">
			<view>
				<input type="text" value="" placeholder="新密码" v-model="newPassword" />
			</view>
			<button type="default" @click="updatePasword">修改密码</button>
		</view>
		<view class="content">
			<button type="default" @click="updateGetuiToken">设置个推token</button>
		</view>
		<view class="content">
			<button type="default" @click="geTuiRecord">获取所有个推记录</button>
		</view>
		<view class="content">
			<button type="default" @click="viewGeTuiMsg(1)">七、查看个推信息</button>
		</view>
		<view class="content">
			<button type="default" @click="geTuiUnreadMsg">八、查看个推记录 （获取未读数量）</button>
		</view>
		<view class="content">
			<view>
				<input type="text" value="" placeholder="运单号" v-model="waybillNum" />
			</view>
			<button type="default" @click="getWaybillState">获取运单轨迹</button>
		</view>
		<button type="default" @click="getPromoteConfig">十、（打开APP时）获取轮播图和公告</button>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				params: {
					accountNum: "",					//账号
					passWord: "",					//密码
					recommendNetWork: "赣州总部",	//推荐网点名称
					recommendNetWorkId: 1,			//推荐网点ID
					tenantId: 1						//租户ID（开发阶段写死  1）
				},
				paramss: {accountNum:"18718514521",passWord:"123456"},
				newPassword: '',
				userInfo: '',
				geTuiRecordParams: {
					"pageNumber": 1,
					"pageSize":10,
					"sort":"createTime",  // 根据创建时间排序
					"order":"desc"
				},
				waybillNum: ''
                
            }
		},
		onLoad() {
            console.log(plus.push.getClientInfo(),77777)
        },
		methods: {
            do(){
                // console.log(plus.push.getClientInfo(),77777)
            },
			showUserInfo(){
				uni.getStorage({
					key: '$userInfo',
					success: (d) => {
						console.log(JSON.stringify(d.data), 8)
						this.userInfo = d.data
					}
				})
			},
            goto(url) {
                uni.navigateTo({
                    url: url
                })
            },
			// 二、登录
			customerLogin(){
				uni.showLoading();
				this.app.apiAsync(`/dfApp/customerLogin`, JSON.stringify(this.paramss), "POST")
				.then( r => {
					r = r.data
					uni.hideLoading();
					if ( r.code == 200 ) {
						uni.setStorage({
							key: '$userInfo',
							data: r.result
						})
					}
					this.app.toast(r.message)
				})
			},
			// 三、注册
			customerRegistered(){
				uni.showLoading();
				this.app.apiAsync(`/dfApp/customerRegistered`, JSON.stringify(this.params), "POST")
				.then( r => {
					uni.hideLoading();
					if ( r.code == 200 ) {
						
					}
					this.app.toast(r.data.message)
				})
			},
			// 四、获取所有推荐网点
			getNetWork(){
				uni.showLoading();
				this.app.apiAsync(`/dfApp/getNetWork?tenantId=1`, {}, "POST")
				.then( r => {
					r = r.data
					uni.hideLoading();
					if ( r.code == 200 ) {
						
					}
					this.app.toast(r.message)
				})
			},
			// 四、修改密码
			updatePasword(){
				let clientId = this.userInfo.client.id
				let username = this.userInfo.client.accountNum
				let token = this.userInfo.token
				
				uni.showLoading();
				this.app.apiAsync(
					`/dfApp/updatePasword?clientId=${clientId}&username=${username}&newPassword=${this.newPassword}&validation=0000`, 
					{}, 
					"POST",
					token
				).then( r => {
					r = r.data
					uni.hideLoading();
					if ( r.code == 200 ) {
						
					}
					this.app.toast(r.message)
				})
			},
			// 执行设置个推token
			doUpdateGetuiToken(id, getuitoken, token){
				
			},
			// 五、设置个推token 
			updateGetuiToken(){
				let id = this.userInfo.client.id
				let getuitoken = plus.push.getClientInfo().clientid // clientid 
				let token = this.userInfo.token
				console.info({id: id, getuitoken: getuitoken},888)
				this.app.apiAsync( `/client/updateGetuiToken`, {id: id, getuitoken: getuitoken}, "POST", token)
				.then( r => {
					r = r.data
					uni.hideLoading();
					if ( r.code == 200 ) {
						console.info(r,999)
					}
					this.app.toast(r.message)
				})
			},
			// 六、获取所有个推记录
			geTuiRecord(){
				let token = this.userInfo.token
				uni.showLoading();
				this.app.apiAsync( `/dfApp/geTuiRecord`, JSON.stringify(this.geTuiRecordParams), "POST", token)
				.then( r => {
					r = r.data
					uni.hideLoading();
					if ( r.code == 200 ) {
						console.info(r,1010)
					}
					this.app.toast(r.message)
				})
			},
			// 七、查看个推信息 dfApp/viewGeTuiMsg?id=个推消息ID
			viewGeTuiMsg(geTuiMsgId){
				let token = this.userInfo.token
				uni.showLoading();
				this.app.apiAsync( `/dfApp/viewGeTuiMsg?id=${geTuiMsgId}`, {}, "POST", token)
				.then( r => {
					r = r.data
					uni.hideLoading();
					if ( r.code == 200 ) {
						
					}
					this.app.toast(r.message)
				})
			},
			// 八、查看个推记录 （获取未读数量）dfApp/geTuiUnreadMsg
			geTuiUnreadMsg(){
				let token = this.userInfo.token
				uni.showLoading();
				this.app.apiAsync( `/dfApp/geTuiUnreadMsg`, {}, "POST", token)
				.then( r => {
					r = r.data
					uni.hideLoading();
					if ( r.code == 200 ) {
						
					}
					this.app.toast(r.message)
				})
			},
			// 九、获取运单轨迹
			// dfApp/getWaybillState?waybillNum=”运单单号” hy086a hy035a hy872643812
			getWaybillState(){
				let token = this.userInfo.token
				uni.showLoading();
				this.app.apiAsync( `/dfApp/getWaybillState?waybillNum=${this.waybillNum}`, {}, "POST", token)
				.then( r => {
					r = r.data
					uni.hideLoading();
					if ( r.code == 200 ) {
						
					}
					this.app.toast(r.message)
				})
			},
			// 十、（打开APP时）获取轮播图和公告
			getPromoteConfig(){
				let token = this.userInfo.token
				uni.showLoading();
				this.app.apiAsync( `/dfApp/getPromoteConfig`, {}, "POST", token)
				.then( r => {
					r = r.data
					uni.hideLoading();
					if ( r.code == 200 ) {
						
					}
					this.app.toast(r.message)
				})
			}
			
		}
	}
</script>

<style scoped lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		view{
			width: 100%;
			text-align: center;
			height: 88rpx;
			line-height: 88rpx;
		}
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
